﻿var page = {
    cities: [
        { name: '北京', location: '116.46,39.92' },
        { name: '上海', location: '121.48,31.22' },
        { name: '天津', location: '117.2,39.13' },
        { name: '重庆', location: '106.54,29.59' },
        { name: '石家庄', location: '114.48,38.03' },
        { name: '太原', location: '112.53,37.87' },
        { name: '沈阳', location: '123.38,41.8' },
        { name: '长春', location: '125.35,43.88' },
        { name: '哈尔滨', location: '126.63,45.75' },
        { name: '杭州', location: '120.19,30.26' },
        { name: '大连', location: '121.53,38.88' },
        { name: '济南', location: '117,36.65' },
        { name: '郑州', location: '113.65,34.76' },
        { name: '武汉', location: '114.31,30.52' },
        { name: '长沙', location: '113,28.21' },
        { name: '广州', location: '113.23,23.16' },
        { name: '海口', location: '110.35,20.02' },
        { name: '成都', location: '104.06,30.67' },
        { name: '贵阳', location: '106.71,26.57' },
        { name: '昆明', location: '102.73,25.04' },
        { name: '南昌', location: '115.89,28.68' },
        { name: '西安', location: '108.95,34.27' },
        { name: '西宁', location: '101.74,36.56' },
        { name: '兰州', location: '103.73,36.03' },
        { name: '南宁', location: '108.33,22.84' },
        { name: '乌鲁木齐', location: '87.68,43.77' },
        { name: '呼和浩特', location: '111.65,40.82' },
        { name: '拉萨', location: '91.11,29.97' },
        { name: '银川', location: '106.27,38.47' },
        { name: '台湾', location: '121.5,25.14' },
        { name: '香港', location: '114.1,22.2' },
        { name: '澳门', location: '113.33,22.13' },
        { name: '合肥', location: '117.27,31.86' },
        { name: '南京', location: '118.78,32.04' }
    ],
    currentCity: 0,

    /* 此方法在第一次显示窗体前发生 */
    onLoad: function (event) {
        console.dir(event);
        this.currentCity = event;
        this.setData({ currentCity: { value: this.currentCity.name } });
        var cityList = new Array()
        for (var i = 0, len = this.cities.length; i < len; i++) {
            var cityItem = new Object();
            cityItem.cityName = new Object();
            cityItem.cityName.value = this.cities[i].name;
            cityItem.cityName.id = "ctiy" + i;
            cityList.push(cityItem);
        }
        this.setData({ city_list: { list: { page: this, items: [{ xml: "Panels/CityItem", items: cityList }] } } });        
    },

    /* 此方法展示窗体后发生 */
    onResume: function (event) {

    },

    /* 当前页状态变化为显示时触发 */
    onShow: function (event) {

    },

    /* 当前页状态变化为隐藏时触发 */
    onHide: function (event) {

    },

    /* 此方法关闭窗体前发生 */
    onExit: function (event) {

    },

    //城市列表按钮回调
    chooseCity: function (event) {
        var index = parseInt(event.target.id.substring(4));
        this.currentCity = this.cities[index]
        this.setData({ currentCity: { value: this.currentCity.name, refresh: true } });
    },
    
    onBack : function(event){
        var obj = new Object();
        obj.page = "cityPage";
        obj.name = this.currentCity.name;
        obj.location = this.currentCity.location;
        pm.navigateBack({ value: obj });        
    },
};

Page(page);

page = 0;
